import {defineStore} from 'pinia';
import routes from "@/router/routes.js";
import {useRoute, useRouter} from "vue-router";
import {useTagsViewStore} from "@/stores/TagsView.js";

// setup
export const useMenuStore = defineStore("menus", () => {
    const currentRoute = useRoute();
    const router = useRouter();
    const TagsViewStore = useTagsViewStore();

    // 菜单列表
    const menuList = ref([]);

    // 生成菜单
    function generateMenus() {
        return new Promise(async (resolve, reject) => {
            // 直接拿全量 routes，暂时不做权限过滤
            menuList.value = routes[0].children;

            // 添加当前路由标签
            TagsViewStore.addTag({
                path: currentRoute.path,
                meta: currentRoute.meta,
                name: currentRoute.name,
            });

            resolve(menuList.value);
        });
    }

    return {
        menuList,
        generateMenus,
    };
});
